package ij.hkust.gui.laserCtr.DAOSTORM;

import ij.IJ;
import ij.hkust.Camera;
import ij.hkust.Constants;
import ij.hkust.UserSettings;
import ij.hkust.AOTFController.AOTFClient;
import ij.hkust.gui.laserCtr.LaserCtrChooser;
import QuickPALM.AOTFController;

/**
 * send the commands to the device
 * @author liuquan
 *
 */
public class DSTCmdSender extends Thread{
//	private AOTFController aotf = new AOTFController();
	private AOTFClient aotf = AOTFClient.instants;
	@Override
	public void run() {
		//read settings
		if (aotf != null){
			aotf.Write("dau dis\r");
			aotf.Write("dau en\r");
			aotf.Write("dau gain * 255\r");
			aotf.Write("dds a 0 0\r");
			aotf.Write("dds a 1 0\r");
			aotf.Write("dds a 2 0\r");
			aotf.Write("dds a 3 0\r");
			aotf.Write("dds a 4 0\r");
			aotf.Write("dds a 5 0\r");
			for(int i=0;i<UserSettings.dstLasers.size();i++){
				aotf.Write("dds a " +Constants.laserID.get(UserSettings.dstLasers.get(i)) +" " +UserSettings.dstLaserInt.get(i) +  "\r");
				aotf.Write("dds f " +Constants.laserID.get(UserSettings.dstLasers.get(i)) +" " + Constants.laserFH.get(UserSettings.dstLasers.get(i)) +  "\r");
			}
			Camera.imageCount = Integer.MAX_VALUE;
//			IJ.log("start cmd...");
			if(LaserCtrChooser.instance.isUsingCamera()){
				IJ.run("cameraSequence");
			}
		}
	}
	public void stopCmd(){
		Camera.imageCount = 0;
		aotf.Write("dds a 0 0\r");
		aotf.Write("dds a 1 0\r");
		aotf.Write("dds a 2 0\r");
		aotf.Write("dds a 3 0\r");
		aotf.Write("dds a 4 0\r");
		aotf.Write("dds a 5 0\r");
		aotf.Write("dau dis\r");
		//aotf.Close();
	}
	
}
